home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 131 / XENIATGM131.iso / Shareware / openOffice.org 641 / Windows / f_0266 / AutoPilotRun.xba next >
Extensible Markup Language  |  2001-11-19  |  14KB  |  392 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="AutoPilotRun" script:language="StarBasic">Option Explicit
  4.  
  5. Public SourceDir as String
  6. Public TargetDir as String
  7. Public TargetStemDir as String
  8. Public SourceFile as String
  9. Public TargetFile as String
  10. Public Source as String
  11. Public SubstFile as String
  12. Public SubstDir as String
  13. Public NoArgs()
  14. Public FilterList(6) as String
  15. Public GoOn as Boolean
  16. Public DoUnprotect as Integer
  17. Public Password as String
  18. Public DocIndex as Integer
  19. Public oPathSettings as Object
  20. Public oDocInfo as Object
  21. Public oUcb as Object
  22. Public TotDocCount as Integer
  23. Public sTotDocCount as String
  24. Public OpenProperties(1) as New com.sun.star.beans.PropertyValue
  25.  
  26.  
  27. Sub StartAutoPilot()
  28. Dim i As Integer
  29.     BasicLibraries.LoadLibrary("Tools")
  30.     If InitResources("Euro Converter", "eur") Then
  31.         oDocInfo = CreateUnoService("com.sun.star.document.DocumentProperties")
  32.         oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess")
  33.         oLocale = GetStarOfficeLocale()
  34.         InitializeConverter(oLocale, 2)
  35.         ToggleGoOnButton()
  36.         DialogModel.cmdGoOn.DefaultButton = True
  37.         DialogConvert.GetControl("optWholeDir").SetFocus()
  38.         DialogConvert.Execute
  39.     End If
  40. End Sub
  41.  
  42.  
  43. Sub ConvertDocuments()
  44. Dim FilesList()
  45. Dim bDisposable as Boolean
  46.  
  47.     If Source <> "" And TargetDir <> "" Then
  48.         If DialogModel.optSingleFile.State = 1 Then
  49.             SourceFile = Source
  50.             TotDocCount = 1
  51.         Else
  52.             SourceDir = Source
  53.             TargetStemDir = TargetDir
  54.             FilterList(0) = "application/x-starcalc"
  55.             FilterList(1) = "application/vnd.stardivision.calc"
  56.             FilterList(2) = "application/vnd.sun.xml.calc"
  57.             If DialogModel.chkTextDocuments.State = 1 Then
  58.                 ReDim Preserve FilterList(6) as String
  59.                 FilterList(3) = "application/x-starwriter"
  60.                 FilterList(4) = "application/vnd.stardivision.writer"
  61.                 FilterList(5) = "application/vnd.stardivision.writer/web"
  62.                 FilterList(6) = "application/vnd.sun.xml.writer"
  63.             End If
  64.             FilesList() = ReadDirectories(SourceDir, bRecursive, True, False, FilterList())
  65.             TotDocCount = Ubound(FilesList(),1) + 1
  66.         End If
  67.         InitializeProgressPage(DialogModel)
  68. '        ChangeToNextProgressStep()
  69.         sTotDocCount = CStr(TotDocCount)
  70.         OpenProperties(0).Name = "Hidden"
  71.         OpenProperties(0).Value = True
  72.         OpenProperties(1).Name = "AsTemplate"
  73.         OpenProperties(1).Value = False
  74.         For DocIndex = 0 To TotDocCount - 1
  75.             If InitializeDocument(FilesList(), bDisposable) Then
  76.                 If StoreDocument() Then
  77.                     ConvertDocument()
  78.                     oDocument.Store
  79.                 End If
  80.                 If bDisposable Then
  81.                     oDocument.Dispose()
  82.                 End If
  83.             End If
  84.         Next DocIndex
  85.         DialogModel.cmdBack.Enabled = True
  86.         DialogModel.cmdGoOn.Enabled = True
  87.         DialogModel.cmdGoOn.Label = sReady
  88.         DialogModel.cmdCancel.Label = sEnd
  89.     End If
  90. End Sub
  91.  
  92.  
  93. Function InitializeDocument(FilesList(), bDisposable as Boolean) as Boolean
  94. ' The Autopilot is started from step No. 2
  95. Dim sViewPath as String
  96. Dim bIsReadOnly as Boolean
  97. Dim sExtension as String
  98.     On Local Error Goto NEXTFILE
  99.     If Not bCancelTask Then
  100.         If DialogModel.optWholeDir.State = 1 Then
  101.             SourceFile = FilesList(DocIndex,0)
  102.             TargetFile = ReplaceString(SourceFile,TargetStemDir,SourceDir)
  103.             TargetDir = DirectorynameoutofPath(TargetFile, "/")
  104.         Else
  105.             SourceFile = Source
  106.             TargetFile = TargetDir & "/" & FileNameoutofPath(SourceFile, "/")
  107.         End If
  108.         If CreateFolder(TargetDir) Then
  109.             sExtension = GetFileNameExtension(SourceFile, "/")
  110.              oDocument = OpenDocument(SourceFile, OpenProperties(), bDisposable)
  111.             If (oDocument.IsReadOnly) AND (UCase(SourceFile) = UCase(TargetFile)) Then
  112.                 bIsReadOnly = True
  113.                 Msgbox(sMsgDOCISREADONLY, 16, GetProductName())
  114.             Else
  115.                 bIsReadOnly = False
  116.                 RetrieveDocumentObjects()
  117.                 sViewPath = CutPathView(SourceFile, 60)
  118.                 DialogModel.lblCurDocument.Label = Str(DocIndex+1) & "/" & sTotDocCount & "  (" & sViewPath & ")"
  119.             End If
  120.             InitializeDocument() = Not bIsReadOnly
  121.         Else
  122.             InitializeDocument() = False
  123.         End If
  124.     Else
  125.         InitializeDocument() = False
  126.     End If
  127. NEXTFILE:
  128.     If Err <> 0 Then
  129.         InitializeDocument() = False
  130.         Resume LETSGO
  131. LETSGO:
  132.     End If
  133. End Function
  134.  
  135.  
  136. Sub ChangeToNextProgressStep()
  137.     DialogModel.lblCurProgress.FontWeight = com.sun.star.awt.FontWeight.NORMAL
  138.     DialogConvert.GetControl("lblCurProgress").Visible = True
  139. End Sub
  140.  
  141.  
  142. Function StoreDocument() as Boolean
  143. Dim sCurFileExists as String
  144. Dim iOverWrite as Integer
  145.     If (TargetFile <> "") And (Not bCancelTask) Then
  146.         On Local Error Goto NOSAVING
  147.         If oUcb.Exists(TargetFile) Then
  148.             sCurFileExists = ReplaceString(sMsgFileExists, ConvertFromUrl(TargetFile), "<1>")
  149.             sCurFileExists = ReplaceString(sCurFileExists, chr(13), "<CR>")
  150.             iOverWrite = Msgbox (sCurFileExists, 32 + 3, sMsgDLGTITLE)
  151.             Select Case iOverWrite
  152.                 Case 1    ' OK
  153.                 Case 2     ' Abort
  154.                     bCancelTask = True
  155.                     StoreDocument() = False
  156.                     Exit Function
  157.                 Case 7     ' No
  158.                     StoreDocument() = False
  159.                     Exit Function
  160.             End Select
  161.         End If
  162.         If TargetFile <> SourceFile Then
  163.             oDocument.StoreAsUrl(TargetFile,NoArgs)
  164.         Else
  165.             oDocument.Store
  166.         End If
  167.         StoreDocument() = True
  168.         NOSAVING:
  169.         If Err <> 0 Then
  170.             StoreDocument() = False
  171.             Resume CLERROR
  172.         End If
  173.         CLERROR:
  174.     End If
  175. End Function
  176.  
  177.  
  178. Sub SwapExtent()
  179.     DialogModel.chkRecursive.Enabled = DialogModel.optWholeDir.State = 1
  180.     If DialogModel.optWholeDir.State = 1 Then
  181.         DialogModel.lblSource.Label = sSOURCEDIR     '"Quellverzeichnis:"
  182.         If Not IsNull(SubstFile) Then
  183.             SubstFile = DialogModel.txtSource.Text
  184.             DialogModel.txtSource.Text = SubstDir
  185.         End If
  186.     Else
  187.         DialogModel.LblSource.Label = sSOURCEFILE   '"Quelldatei:"
  188.         If Not IsNull(SubstDir) Then
  189.             SubstDir = DialogModel.txtSource.Text
  190.             DialogModel.txtSource.Text = SubstFile
  191.         End If
  192.     End If
  193.     ToggleGoOnButton()
  194. End Sub
  195.  
  196.  
  197. Sub    InitializeThirdStep()
  198. Dim TextBoxText as String
  199.     Source = AssignFileName(DialogModel.txtSource.Text, DialogModel.lblSource.Label, True)
  200.     TargetDir = AssignFileName(DialogModel.txtTarget.Text, DialogModel.lblTarget.Label, False)
  201.     If Source <> "" And TargetDir <> "" Then
  202.         bRecursive = DialogModel.chkRecursive.State = 1
  203.         bDoUnprotect = DialogModel.chkProtect.State = 1
  204.         DialogModel.lblRetrieval.FontWeight = com.sun.star.awt.FontWeight.BOLD
  205.         DialogModel.lblRetrieval.Label = sPrgsRETRIEVAL
  206.         DialogModel.lblCurProgress.Label = sPrgsCONVERTING
  207.         If DialogModel.optWholeDir.State = 1 Then
  208.             TextBoxText = sSOURCEDIR & " " & ConvertFromUrl(Source) & chr(13) '& " "
  209.             If DialogModel.chkRecursive.State = 1 Then
  210.                 TextBoxText = TextBoxText & DeleteStr(sInclusiveSubDir,"~") & chr(13)
  211.             End If
  212.         Else
  213.             TextBoxText = sSOURCEFILE & " " & ConvertFromUrl(Source) & chr(13) 
  214.         End If
  215.         TextBoxText = TextBoxText & sTARGETDIR & " " & ConvertFromUrl(TargetDir) & chr(13)
  216.         If DialogModel.chkProtect.State = 1 Then
  217.             TextBoxText = TextboxText & sPrgsUNPROTECT
  218.         End If
  219.         DialogModel.txtConfig.Text = TextBoxText
  220.          ToggleProgressStep()
  221.         DialogModel.cmdGoOn.Enabled = False     
  222.      End If
  223. End Sub
  224.  
  225.  
  226. Sub ToggleProgressStep(Optional aEvent as Object)
  227. Dim bMakeVisible as Boolean
  228. Dim LocStep as Integer
  229.     ' If the Sub is call by the 'cmdBack' Button then set the 'bMakeVisible' variable accordingly
  230.     bMakeVisible = IsMissing(aEvent)
  231.     If bMakeVisible Then
  232.         DialogModel.Step = 3
  233.     Else
  234.         DialogModel.Step = 2
  235.     End If
  236.      DialogConvert.GetControl("lblCurrencies").Visible = Not bMakeVisible
  237.      DialogConvert.GetControl("lstCurrencies").Visible = Not bMakeVisible
  238.     DialogConvert.GetControl("cmdBack").Visible = bMakeVisible
  239.      DialogConvert.GetControl("cmdGoOn").Visible = bMakeVisible
  240.     DialogModel.imgPreview.ImageUrl = BitmapDir & "euro_" & DialogModel.Step & ".bmp"         
  241. End Sub
  242.  
  243.  
  244. Sub EnableStep2DialogControls(OnValue as Boolean)
  245.     With DialogModel
  246.         .hlnExtent.Enabled = OnValue
  247.         .optWholeDir.Enabled = OnValue
  248.         .optSingleFile.Enabled = OnValue
  249.         .chkProtect.Enabled = OnValue
  250.         .cmdCallSourceDialog.Enabled = OnValue
  251.         .cmdCallTargetDialog.Enabled = OnValue
  252.         .lblSource.Enabled = OnValue
  253.         .lblTarget.Enabled = OnValue
  254.         .txtSource.Enabled = OnValue
  255.         .txtTarget.Enabled = OnValue
  256.         .imgPreview.Enabled = OnValue
  257.         .lstCurrencies.Enabled = OnValue
  258.         .lblCurrencies.Enabled = OnValue
  259.         If OnValue Then
  260.             ToggleGoOnButton()
  261.             .chkRecursive.Enabled = .optWholeDir.State = 1
  262.         Else
  263.             .cmdGoOn.Enabled = False
  264.             .chkRecursive.Enabled = False
  265.         End If
  266.     End With
  267. End Sub
  268.  
  269.  
  270. Sub InitializeProgressPage()
  271.     DialogConvert.GetControl("lblRetrieval").Visible = False
  272.     DialogConvert.GetControl("lblCurProgress").Visible = False
  273.     DialogModel.lblRetrieval.FontWeight = com.sun.star.awt.FontWeight.NORMAL
  274.     DialogModel.lblCurProgress.FontWeight = com.sun.star.awt.FontWeight.BOLD
  275.     DialogConvert.GetControl("lblRetrieval").Visible = True
  276.     DialogConvert.GetControl("lblCurProgress").Visible = True
  277. End Sub
  278.  
  279.  
  280. Function AssignFileName(sPath as String, ByVal HeaderString, bCheckFileType as Boolean) as String
  281. Dim bIsValid as Boolean
  282. Dim sLocMimeType as String
  283. Dim sNoDirMessage as String
  284.     HeaderString = DeleteStr(HeaderString, ":")
  285.     sPath = ConvertToUrl(Trim(sPath))
  286.     bIsValid = oUcb.Exists(sPath)
  287.     If bIsValid Then
  288.         If DialogModel.optSingleFile.State = 1 Then
  289.             If bCheckFileType Then
  290.                 sLocMimeType = GetRealFileContent(oDocInfo, sPath)
  291.                 If DialogModel.chkTextDocuments.State = 1 Then
  292. 'Todo: Neue Resource aufsetzen mit Hinweis, dass Writer oder Calc Dokument ausgew├ñhlt werden muss
  293.                     If (Instr(1, sLocMimeType, "writer") = 0) And (Instr(1, sLocMimeType, "calc") = 0) Then
  294.                         Msgbox(sMsgFileInvalid, 48, sMsgDLGTITLE)
  295.                         bIsValid = False                        
  296.                     End If                
  297.                 Else
  298.                     If Instr(1, sLocMimeType, "calc") = 0 Then
  299.                         Msgbox(sMsgFileInvalid, 48, sMsgDLGTITLE)
  300.                         bIsValid = False
  301.                     End If
  302.                 End If
  303.             End If
  304.         Else
  305.             If Not oUcb.IsFolder(sPath) Then
  306.                 sNoDirMessage = ReplaceString(sMsgNODIRECTORY,sPath,"<1>")
  307.                 Msgbox(sNoDirMessage,48, sMsgDLGTITLE)
  308.                 bIsValid = False
  309.             Else
  310.                 sPath = RTrimStr(sPath,"/")
  311.                 sPath = sPath & "/"
  312.             End If
  313.         End if
  314.     Else
  315.         Msgbox(HeaderString & " '" & ConvertFromUrl(sPath) & "' " &  sMsgNOTTHERE,48, sMsgDLGTITLE)
  316.     End If
  317.     If bIsValid Then
  318.         AssignFileName() = sPath
  319.     Else
  320.         AssignFilename() = ""
  321.     End If
  322. End Function
  323.  
  324.  
  325. Sub ToggleGoOnButton()
  326. Dim bDoEnable as Boolean    
  327. Dim sLocMimeType as String
  328. Dim sPath as String
  329.     bDoEnable = Ubound(DialogModel.lstCurrencies.SelectedItems()) > -1
  330.     If bDoEnable Then
  331.         ' Check if Source is set correctly
  332.         sPath = ConvertToUrl(Trim(DialogModel.txtSource.Text))
  333.         bDoEnable = oUcb.Exists(sPath)
  334.     End If
  335.     If bDoEnable Then
  336.         ' Check if Source is set correctly
  337.         sPath = ConvertToUrl(Trim(DialogModel.txtTarget.Text))
  338.         bDoEnable = oUcb.Exists(sPath)
  339.     End If
  340.     DialogModel.cmdGoOn.Enabled = bDoEnable
  341. End Sub
  342.  
  343.  
  344. Sub CallFolderPicker()
  345.     GetFolderName(DialogModel.txtTarget)
  346.     ToggleGoOnButton()    
  347. End Sub
  348.  
  349.  
  350. Sub CallFilePicker()
  351.     If DialogModel.optSingleFile.State = 1 Then
  352.         Dim oMasterKey as Object
  353.         Dim oTypes() as Object
  354.         Dim oUIKey() as Object
  355.         
  356.         oMasterKey = GetRegistryKeyContent("org.openoffice.Office.TypeDetection/")
  357.         oTypes() = oMasterKey.Types
  358.         oUIKey = GetRegistryKeyContent("org.openoffice.Office.UI/FilterClassification/LocalFilters")
  359.         If DialogModel.chkTextDocuments.State = 1 Then
  360.             Dim FilterNames(7,1) as String
  361.             FilterNames(4,0) = oTypes.GetByName("writer_StarOffice_XML_Writer").UIName
  362.             FilterNames(4,1) = "*.sxw"
  363.             FilterNames(5,0) = oTypes.GetByName("writer_StarOffice_XML_Writer_Template").UIName
  364.             FilterNames(5,1) = "*.stw"
  365.             FilterNames(6,0) = oUIKey.Classes.GetByName("sw3to5").DisplayName
  366.             FilterNames(6,1) = "*.sdw"
  367.             FilterNames(7,0) = oUIKey.Classes.GetByName("sw3to5templ").DisplayName
  368.             Filternames(7,1) = "*.vor"
  369.         Else
  370.             ReDim FilterNames(3,1) as String
  371.         End If
  372.         FilterNames(0,0) = oTypes.GetByName("calc_StarOffice_XML_Calc").UIName    
  373.         Filternames(0,1) = "*.sxc"
  374.         FilterNames(1,0) = oTypes.GetByName("calc_StarOffice_XML_Calc_Template").UIName
  375.         Filternames(1,1) = "*.stc"
  376.         FilterNames(2,0) = oUIKey.Classes.GetByName("sc345").DisplayName
  377.         FilterNames(2,1) = "*.sdc"
  378.         FilterNames(3,0) = oUIKey.Classes.GetByName("sc345templ").DisplayName
  379.         Filternames(3,1) = "*.vor"
  380.         GetFileName(DialogModel.txtSource, Filternames())
  381.     Else
  382.         GetFolderName(DialogModel.txtSource)
  383.     End If
  384.     ToggleGoOnButton()
  385. End Sub
  386.  
  387.  
  388. Sub PreviousStep()
  389.     DialogModel.Step = 2
  390.     DialogModel.cmdGoOn.Label =  sGOON
  391.     DialogModel.cmdCancel.Label = sCANCEL
  392. End Sub</script:module>